<template>
  <!-- 文件管理新增按钮弹窗 -->
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    okText="打印"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">
        <p-row>
          <p-col :span="12">
            <p-form-item label="标签模板编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input readonly disabled placeholder="标签模板编码" v-model="EnhanceJS.labelTemplateNo" ></p-input>
            </p-form-item>
          </p-col>
          <p-col :span="12">
            <p-form-item label="标签模板名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input readonly disabled v-model="EnhanceJS.labelTemplateName" placeholder="标签模板名称"></p-input>
            </p-form-item>
          </p-col>
          <p-col :span="12">
            <p-form-item label="标签模板描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input readonly disabled  v-model="EnhanceJS.labelTemplateDescrtion" placeholder="标签模板描述"></p-input>
            </p-form-item>
          </p-col>
          <p-col :span="12">
            <p-form-item label="标签模板尺寸" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input readonly disabled  v-model="EnhanceJS.labelTemplateLength" placeholder="标签模板尺寸"></p-input>
            </p-form-item>
          </p-col>
          <p-col :span="12">
            <p-form-item label="责任部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input readonly disabled  v-model="EnhanceJS.dptname" placeholder="责任部门"></p-input>
            </p-form-item>
          </p-col>
          <p-col :span="12">
            <p-form-item label="标签纸颜色" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input readonly disabled  v-model="EnhanceJS.labelColor" placeholder="标签纸颜色"></p-input>
            </p-form-item>
          </p-col>
          <p-col :span="12">
            <p-form-item label="碳带型号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input readonly disabled  v-model="EnhanceJS.ribbonsType" placeholder="碳带型号"></p-input>
            </p-form-item>
          </p-col>
          <p-col :span="12">
            <p-form-item label="打印机型号 " :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input readonly disabled  v-model="EnhanceJS.printerType" placeholder="打印机型号"></p-input>
            </p-form-item>
          </p-col>
          <p-col :span="12">
            <p-form-item label="打印份数" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <p-input   v-model="EnhanceJS.fileType" placeholder="打印份数"></p-input>
            </p-form-item>
          </p-col>
        </p-row>
      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>
import { SubmitOnchangMixin } from "@/mixins/SubmitOnchangMixin";
import { httpAction, putAction, api } from "@/api/manage";
import pick from "lodash.pick";
import JUpload from "@/components/jeecg/JUpload";
import JDictSelectTag from "@/components/dict/JDictSelectTag";

export default {
  name: "MesQcQualityFileManagementModal",
  mixins: [SubmitOnchangMixin],
  components: {
    JUpload,
    JDictSelectTag,
  },
  props:{
      EnhanceJS:{
        default:'',
        required:false
      }
    },
  data() {
    return {
      form: this.$form.createForm(this),
      title: "基础信息",
      width: 1000,
      visible: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },

      confirmLoading: false,
      validatorRules: {
        labelTemplateNo: { rules: [{ required: true, message: "请输入模板编码!" }] },
        labelTemplateName: { rules: [{ required: true, message: "请输入模板名称!" }] },
        labelTemplateDescrtion: {rules: [{ required: true, message: "请输入模板描述" }],},
        labelTemplateLength: { rules: [{ required: true, message: "请输入模板尺寸" }] },
        dptname: { rules: [{ required: true, message: "责任部门" }] },
        labelColor: { rules: [{ required: true, message: "标签纸颜色!" }] },
        ribbonsType: { rules: [{ required: true, message: "碳带型号!" }] },
        printerType: { rules: [{ required: true, message: "打印机型号!" }] },
        fileType: { rules: [{ required: true, message: "打印份数!" }] },
      },
      url: {
        add: "/mes-quality/mesQcQualityFileManagement/add",
        edit: "/mes-quality/mesQcQualityFileManagement/edit",
      },
    };
  },
  created() {},
  methods: {
    add() {
      this.edit({});
      this.getRuleCodeValue();
    },
    getRuleCodeValue() {
      let param = {
        commonFormData: this.model,
        rules: [{ ruleCode: "mes_quality_file_rule", columnName: "fileCode" }],
      };

      putAction(api.ruleBaseURL, param).then((res) => {
        // 执行成功，获取返回的值，并赋到页面上
        if (res.success) {
          console.log("生成的编码：" + res.data);
        }
      });
    },
    edit(record) {
      this.form.resetFields();
      this.model = Object.assign({}, record);
      this.visible = true;
      this.$nextTick(() => {
        this.form.setFieldsValue(
          pick(
            this.model,
            "fileCode",
            "fileName",
            "fileVersion",
            "fileUrl",
            "fileType",
            "createBy",
            "createTime",
            "updateBy",
            "updateTime",
            "remarks",
            "status"
          )
        );
      });
    },
    close() {
      this.$emit("close");
      this.visible = false;
    },
    handleOk() {
      if(this.EnhanceJS.fileType){
        var href = this.EnhanceJS.ureportAddress 
            // var href="http://192.168.6.145/fx-platform/ureport/preview?_u=mysql-%E5%B0%8F%E6%A0%87%E7%AD%BE%E6%B5%8B%E8%AF%95.ureport.xml&"+ id
            this.$router.push({
              path: `/layouts/IframePageRouter?=${href}`,
            })
            this.visible = false;
      }else{
        this.$message.warning("请输入打印份数");
      }
      
    },
    handleCancel() {
      this.close();
    },
    popupCallback(row) {
      this.form.setFieldsValue(
        pick(
          row,
          "fileCode",
          "fileName",
          "fileVersion",
          "fileUrl",
          "fileType",
          "createBy",
          "createTime",
          "updateBy",
          "updateTime",
          "remarks",
          "status"
        )
      );
    },
  },
};
</script>
